package vcp.views;

import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

import javax.swing.event.AncestorListener;
import javax.swing.text.html.HTMLDocument.Iterator;

import client.Message;
import db.parking.beans.Complaints;
import vcp.common.AbstractView;
import vcp.common.IView;
import vcp.gui.forms.ResolveComplaintsForm;

public class ResolveComplaintsView extends AbstractView implements Observer,
		IView {
	boolean complaintsTableLoaded = false;
	ResolveComplaintsForm complaintsForm;

	public ResolveComplaintsView() {
		complaintsForm = new ResolveComplaintsForm();
	}

	public ResolveComplaintsForm getComplaintsForm() {
		return complaintsForm;
	}

	@Override
	public void addController(Object obj) {
		// need to listen if parent panel loaded
		this.complaintsForm.addAncestorListener(
				(AncestorListener) obj);
		
	}

	@Override
	public void update(Observable arg0, Object arg) {
		Message recvmsg = (Message) arg;
		if (recvmsg.getMsg().equals("GetComplaints") && complaintsTableLoaded==false) {
			ArrayList<Complaints> list = 
					(ArrayList<Complaints>) recvmsg.getObj();
			java.util.Iterator<Complaints> itty = list.iterator();
			Object obj[] = new Object[4];
			while (itty.hasNext()) {
				Complaints c = (Complaints) itty.next();
				obj[0] = c.getCustomerID();
				obj[1] = c.getOrderID();
				obj[2] = c.getTitle();
				obj[3] = Boolean.parseBoolean(Integer.toString(c.getStatus()));
				this.complaintsForm.getDtm().addRow(obj);
			}
			complaintsTableLoaded = true;
		}
	}

}
